﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using Sim;
using Lists;
using System.Threading.Tasks;
using System.Threading;
using ClientApplication;
using Sim.Lists;

namespace Sim
{
    static public class Program
    {
        public struct clientUser
        {
            public string username;
            public string gender;
            public string nation;
            public string level;
            public string round;
            public string inTournament;

        }

        static public bool flagg = false;
        static public bool isLoggedIn = false;
        static public bool isConnected = false;

        public struct TournamentRegister
        {
            public string username;
            public string tournamentTitle;

            public TournamentRegister(string username, string tournamentTitle)
            {
                this.username = username;
                this.tournamentTitle = tournamentTitle;
            }
        }

        static public List<TournamentRegister> tr = new List<TournamentRegister>();

        static public UserList ul = new UserList();
        static public TournamentList tl = new TournamentList();
        static public ClientApplications ca = new ClientApplications();
        static public clientUser cu = new clientUser();

        //=======ADMIN========
        public struct userInfo
        {
            public string id;
            public string username;
            public string firstname;
            public string lastname;
            public string age;
            public string gender;
            public string nation;
            public string level;

            public userInfo(string id, string username, string firstname, string lastname, string age, string gender, string nation, string level)
            {
                this.id = id;
                this.username = username;
                this.firstname = firstname;
                this.lastname = lastname;
                this.age = age;
                this.gender = gender;
                this.nation = nation;
                this.level = level;
            }
        }
        static public List<Tournament> ti = new List<Tournament>();
        static public List<userInfo> ui = new List<userInfo>();
        

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            try
            {

                ca.myIP = IPList.GetPublicIP();
            }
            catch (Exception ex)
            {
                while (ca.myIP == null)
                {
                    Thread.Sleep(100);
                    ca.myIP = IPList.GetPublicIP();
                }
            }

            DDList.DeserializeFromXML();

            Main main = new Main();
            Login login = new Login();
            PresenterMain presenter = new PresenterMain(main, login, ul, tl);


            Thread ta = new Thread(ca.Receive);
            ta.Start();
            Application.Run(main);


        }
    }
}
